#include <iostream>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

using namespace std;

int main()
{
    pid_t pid;
    int status;

    pid = fork();
    if (pid < 0) 
    {
        cerr << "fork error" << endl;
        return 1;
    }
    if (pid > 0) 
    {
        cout << "Parent process (PID: " << getpid() << ") exiting immediately" << endl;
        exit(0); 
    }
    else 
    {   
        cout << "Child process (PID: " << getpid() << ") created" << endl;
        sleep(5); 

        cout << "Child process (PID: " << getpid() << ") exiting" << endl;

        pid_t ppid = getppid();
        cout << "Parent process (PID: " << ppid << ") of child process (PID: " << getpid() << ") is exiting" << endl;   
        exit(0);
    }
    return 0;
}